#coding:utf-8

from flask import Flask, session
app = Flask(__name__)


#todo 直接设置session会报错,因为没有秘钥字符串
#RuntimeError: the session is unavailable because no secret key was set.
#todo 而为啥需要秘钥字符串呢?因为flask默认将session存储在cookie中,你会发现cookie中默认多了一个session
#todo 但是这不是安全的,所以另外一种设置session的方法就是将他放入url中
app.config['SECRET_KEY'] = 'adfjaklqerjafdfnqn3w'


@app.route('/login')
def login():
    #todo 设置session
    session['name'] = 'python'
    return 'login success'

@app.route('/index')
def index():
    #todo 获取session数据
    name = session.get('name')
    return 'hello %s ' % name


if __name__ == '__main__':
    app.run(debug=True)

